import { Config } from '../../utils/config.js';

Page({
  data: {
    phone:"",
    fb_content:""
  },


  //输入手机号码
  getPhoneNum: function (e) {
    let phone = e.detail.value.replace(/[^\d]/g, '')
    console.log(phone)
    this.setData({
      phone: phone
    })

    return phone
  },

  //输入反馈内容
  get_fb: function (e) {
    let fb_content = e.detail.value
    console.log(fb_content)
    this.setData({
      fb_content: fb_content
    })

  },




  // 点击确定
  click_submit:function(){
    let that = this
    let phone = that.data.phone;
    let fb_content = this.data.fb_content;
    console.log(phone, fb_content)
    //手机号正则判断
    let myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!myreg.test(phone)) {
      wx.showModal({
        title: '提示',
        content: '手机号错误！',
        showCancel: false
      })
      return;
    };

    if (fb_content=="") {
      wx.showModal({
        title: '提示',
        content: '请填写反馈内容',
        showCancel: false
      })
      return;
    };

    wx.request({
      url: Config.restUrl + 'feedback/invoiceFailFeedback',
      method:'POST',
      dataType: 'json',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data:{
        phone: phone,
        remark: fb_content,
        fpqqlsh: that.data.invoice_transaction
      },
      success:function(data){

        wx.navigateTo({
          url: '/pages/feedback_success/feedback_success',
        })

      },
      fail:function(res){

      }
    })
  },

  onLoad:function(e){
    let that = this;
    let invoice_transaction = e.fpqqlsh
    that.setData({
      invoice_transaction: invoice_transaction
    })
    
  }

})
